

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>banner管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-table-body .layui-table-cell {
            height: 85px;
            line-height: 85px;
        }
        .novel img{
            max-width: 250px !important;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="LAY-recommend" lay-filter="LAY-recommend"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="add">添加号码</button>
                </div>
            </script>
            <script type="text/html" id="typeTpl">
                {{#  if(d.type == 1){ }}
                <span style="color: #5FB878;">广告线上</span>
                {{#  } else if(d.type == 2) { }}
                <span>屏蔽地区</span>
                {{#  } else if(d.type == 0) { }}
                <span style="color: #5FB878;">审核用户</span>
                {{#  } }}
            </script>

            <script type="text/html" id="seatTpl">
                {{#  if(d.seat == 1){ }}
                男频首页
                {{#  } else if(d.seat == 2) { }}
                女频首页
                {{#  } else if(d.seat == 3) { }}
                书架页
                {{#  } else if(d.seat == 0) { }}
                首页
                {{#  } }}
            </script>

            <script type="text/html" id="lxTpl">
                <div class="novel">
                {{#  if(d.content_type == 1){ }}
                    推书
                {{#  } }}
                {{#  if(d.content_type == 2){ }}
                    充值活动
                {{#  } }}
                </div>
            </script>


            <script type="text/html" id="contentTpl">
                <div class="novel">
                    {{#  if(d.content_type == 1){ }}
                    小说 [ID:{{d.novel_id}}]：{{d.novel.title}}
                    {{#  } }}
                    {{#  if(d.content_type == 2){ }}
                    活动 [ID:{{d.activity_id}}]：{{d.activity.title}}
                    {{#  } }}
                </div>
            </script>


            <script type="text/html" id="bannerTpl">
                <div class="novel">
                    <a href="javascript:;" onclick="showImg('__IMG_DOMAIN__{{d.banner}}');"><img src="__IMG_DOMAIN__{{d.banner}}" width="190" height="60"></a>
                </div>
            </script>

            <script type="text/html" id="table-useradmin-admin">
                <a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete" ></i>删除</a>
            </script>
        </div>


    </div>

</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','admin'], function(){
        var $ = layui.$
            ,form = layui.form
            ,admin = layui.admin
            ,table = layui.table;

        form.on('submit(LAY-user-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('LAY-recommend', {
                where: field
                ,page: {
                    curr: 1  // 将页码重置为第一页
                }
            });
        });


        table.render({
            elem: '#LAY-recommend'
            , url: '/tool/paymentalarm' //模拟接口
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: false
            , cellMinWidth: 100
            , response: {
                statusCode: 1 //规定成功的状态码，本来是：0，现在统一改为1
            }
            , page: true //开启分页
            , limits: [10, 20, 30, 50, 100]
            , cols: [
                [
                    {field: 'phone', title: '手机号码',align: 'center'}
                    , {field: 'name', title: '描述',align: 'center'}
                    , {
                    title: '操作',
                    minWidth: 100,
                    align: 'center',
                    fixed: 'right',
                    toolbar: '#table-useradmin-admin',
                }]]
        });


        //监听开关
        form.on('switch(random)', function(data){
            if (data.elem.checked == true) {
                var value = 1;
            } else {
                var value = 0;
            }
            admin.req({
                url: '/website/switchRandom'
                , type: "POST"
                , data: {'id': data.value, 'is_random': value}
                , done: function (res) {
                    layer.msg('设置成功', {icon: 1, time: 1000}, function () {
                    });
                }, not_finish: function (res) {
                    layer.msg(res.msg,function () {
                        table.reload('LAY-recommend');
                    });
                }
            });
        });


        //头工具栏事件
        table.on('toolbar(LAY-recommend)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    layer.open({
                        type: 2
                        ,maxmin: true//开启最大化最小化按钮
                        ,title: '添加号码'
                        ,content: '/tool/addAlarm'
                        ,offset: '5px'
                        ,area: ['500px', '300px']
                        ,btn: ['确定', '取消']
                        ,yes: function(index, layero){
                            var iframeWindow = window['layui-layer-iframe'+ index]
                                ,submit = layero.find('iframe').contents().find("#LAY-user-role-submit");

                            //监听提交
                            iframeWindow.layui.form.on('submit(LAY-user-role-submit)', function(data){
                                var field = data.field; //获取提交的字段
                                console.log(field);
                                //提交 Ajax 成功后，静态更新表格中的数据
                                //$.ajax({});
                                admin.req({
                                    url: '/tool/addAlarm'
                                    , type: "POST"
                                    , data: field
                                    , done: function (res) {
                                        layer.msg('添加成功', {icon: 1, time: 2000}, function () {
                                            table.reload('LAY-recommend');
                                            layer.close(index); //关闭弹层
                                        });
                                    },not_finish:function (res) {
                                        layer.msg(res.msg);
                                    }
                                });
                            });
                            submit.trigger('click');
                        }
                    });
                    break;
            }
        });


        //监听工具条
        table.on('tool(LAY-recommend)', function(obj){
            var data = obj.data;
            if (obj.event === 'del'){
                layer.confirm('【'+obj.data.name+'】确认删除此信息吗？',{icon: 3, title:false}, function(index){
                    admin.req({
                        url: '/tool/delAlarm'
                        , type: "POST"
                        , data: {'id': obj.data.id}
                        , done: function (res) {
                            layer.msg('删除成功', {icon: 1, time: 1000}, function () {
                                obj.del();
                                layer.close(index);
                            });
                        },not_finish:function (res) {
                            layer.msg(res.msg);
                        }
                    });
                });
            }
        });
    });

    function showImg(imgUrl) {
        layui.$("#showImg").prop('src', imgUrl);
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            area: ['auto'],
            skin: 'layui-layer-nobg', //没有背景色
            shadeClose: true,
            content: layui.$('#tong')
        });
    }
</script>
<div id="tong" class="layui-layer-wrap" style="display: none;">
    <a href="javascript:;" target="_blank">
        <img src="" id="showImg" style="height: 500px;">
    </a>
</div>
</body>
</html>

